import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flutter/cupertino.dart';

import 'LFormInputLogic.dart';
import 'LFormInputState.dart';



class LFormInputPage extends StatelessWidget {

  const LFormInputPage({super.key, required this.tag});
  final String tag;



  @override
  Widget build(BuildContext context) {
    final LFormInputState state = Get.find<LFormInputLogic>(tag: tag).state;

    return GetBuilder<LFormInputLogic>(
      // id: state.id,
      // assignId:true,
      // autoRemove:true,
      tag: tag,
      builder: (logic){
        return TextFormField(
          keyboardType:state.formItem["keyboardType"]??TextInputType.text,
          maxLines: state.formItem["maxLines"]??1,
          controller: TextEditingController.fromValue(TextEditingValue(
              text:'${state.formData['${state.formItem["field"]}${state.betweenSign}'] ?? ""}',
              selection: TextSelection.fromPosition(TextPosition(affinity: TextAffinity.downstream,offset: '${state.formData['${state.formItem["field"]}${state.betweenSign}'] ?? ""}'.length))
          )),
          // initialValue: widget.formData[widget.item['field']],
          readOnly: state.formItem["readonly"]??false,
          autofocus: state.formItem["autofocus"]??false,
          decoration: const InputDecoration(
            hintText: "请输入",
            hintStyle: TextStyle(fontSize: 16),
            enabledBorder: InputBorder.none,
            focusedBorder: InputBorder.none,
            disabledBorder: InputBorder.none,
          ),

          onChanged:(v){ //监听输入框值变化
            logic.onChanged(v);
          },
          onSaved: (v){
            //赋值
            logic.onSaved(v);
          },
          validator: (v){
            return logic.onValidator(v);
          },

        );
      },
    );
  }
  
}